<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends Controller{
	public function _initialize(){
		$this -> user = D('User');
	}
	public function userlist(){
		$name = $_POST['name'];
		$ctime = $_POST['ctime'];
		if ($name) {
			$where['name'] = array("like","%$name%");
		}
		if ($ctime) {
			$where['ctime'] = array("lt",strtotime($ctime));
		}
		$count =  $this -> user -> where($where)->count();
		$page = new \Think\Page($count,15);
		if ($name) {
        	$page->parameter['name'] =  $name;
		}
		$userlist = $this -> user -> where($where) -> order('ctime desc') -> limit($page->firstRow,$page->listRows) -> select();
		$this -> assign('userlist',$userlist);
		$this -> assign('page',$page->show());
		$this -> display();
	}

	public function updstatus(){
		$data['id'] = $_POST['id'];
		$data['status'] = 1;
		$res = $this -> user -> save($data);
		if ( $res ) {
			apiResponse("success","审核通过！");
		}else{
			apiResponse("error","审核失败！");
		}
	}


    public function expUser(){
        /**获取Excel导出数据*/
        $list  = $this -> user -> Field('id,name,cardid,tel,hy,zhiw,ctime,jnum,status') -> select();  
        /**查出来你要导出的数据*/
        
        $arrordername = array('ID号','名字','身份证','电话','行业','职位','创建时间','举报次数','状态');
        foreach($list as $key=>$val){
        	$val['status']=$val['status']==1?'已审核':'未审核';
            
            $arrorderlist[] = array($val['id'],$val['name'],$val['cardid'],$val['tel'],$val['hy'],$val['zhiw'],date('Y-m-d H:m:i',$val['ctime']),$val['jnum'],$val['status']);
        }
//        //dump($arrorderlist);
//        exit;
        exportexcel($arrorderlist,$arrordername,'供应信息');

    }
}